package com.ourteam.product.ui.dao.impl;

import com.ourteam.product.ui.dao.IProductUIFormLayoutDataDAO;
import com.ourteam.product.ui.dao.ProductUIFormLayoutData;
import com.ourteam.product.ui.dao.ProductUIFormLayoutDataDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-12-14 15:15:17 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractProductUIFormLayoutDataDAOJdbcImpl extends AbstractSpringDAO
    implements IProductUIFormLayoutDataDAO {

  public static final String[] ENTITY_FIELDS = new String[] {Id, FormFieldId, Name, Value};

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.FormFieldId,
        _DataObjectProperty.Name,
        _DataObjectProperty.Value
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<ProductUIFormLayoutData, ProductUIFormLayoutDataDAOQueryBean>
      daoHelper;

  public AbstractProductUIFormLayoutDataDAOJdbcImpl() {
    super();
    daoHelper =
        new DataAccessObjectHelper<ProductUIFormLayoutData, ProductUIFormLayoutDataDAOQueryBean>(
            this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aProductUIFormLayoutData
   * @throws Exception
   */
  public boolean checkIsUnique(ProductUIFormLayoutData aProductUIFormLayoutData) throws Exception {

    if (aProductUIFormLayoutData == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aProductUIFormLayoutData.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aProductUIFormLayoutData
   * @throws Exception
   */
  public void insert(ProductUIFormLayoutData aProductUIFormLayoutData) throws Exception {

    super.doInsert(aProductUIFormLayoutData);
  }

  /**
   * Batch Insert Datas
   *
   * @param aProductUIFormLayoutData
   * @throws Exception
   */
  public void batchInsert(ProductUIFormLayoutData[] aProductUIFormLayoutDatas) throws Exception {

    super.doBatchInsert(aProductUIFormLayoutDatas);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(ProductUIFormLayoutDataDAOQueryBean queryBean) throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(ProductUIFormLayoutData aProductUIFormLayoutData) throws Exception {

    delete(aProductUIFormLayoutData.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aProductUIFormLayoutData
   * @throws Exception
   */
  public void update(ProductUIFormLayoutData aProductUIFormLayoutData) throws Exception {

    if (aProductUIFormLayoutData.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aProductUIFormLayoutData);

    ProductUIFormLayoutData tempObj = findById(aProductUIFormLayoutData.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aProductUIFormLayoutData, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aProductUIFormLayoutDatas[]
   * @throws Exception
   */
  public void batchUpdate(ProductUIFormLayoutData[] aProductUIFormLayoutDatas) throws Exception {

    super.doBatchUpdate(aProductUIFormLayoutDatas);
  }

  /**
   * Update Data By Condictions
   *
   * @param aProductUIFormLayoutData
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(
      ProductUIFormLayoutData aProductUIFormLayoutData,
      ProductUIFormLayoutDataDAOQueryBean aQueryBean)
      throws Exception {

    super.doUpdateByQuery(aProductUIFormLayoutData, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(ProductUIFormLayoutDataDAOQueryBean aQueryBean) throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(ProductUIFormLayoutData aProductUIFormLayoutData) throws Exception {

    if (aProductUIFormLayoutData.getName() == null) {
      throw new Exception("The ProductUIFormLayoutData.name value is not allow NULL");
    }

    if (aProductUIFormLayoutData.getValue() == null) {
      throw new Exception("The ProductUIFormLayoutData.value value is not allow NULL");
    }
  }

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public ProductUIFormLayoutData findById(final long id) throws Exception {

    ProductUIFormLayoutDataDAOQueryBean queryBean = new ProductUIFormLayoutDataDAOQueryBean();

    ProductUIFormLayoutDataDAOQueryBean.Criteria criteria = queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    ProductUIFormLayoutData[] ProductUIFormLayoutDatas = query(queryBean);

    if (ProductUIFormLayoutDatas.length == 0) {
      return null;
    } else {
      return ProductUIFormLayoutDatas[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return ProductUIFormLayoutData[]
   * @throws Exception
   */
  public ProductUIFormLayoutData[] query(ProductUIFormLayoutDataDAOQueryBean queryBean)
      throws Exception {

    List result = super.doQuery(queryBean, new JdbcProductUIFormLayoutDataRowMapper());

    return (ProductUIFormLayoutData[]) result.toArray(new ProductUIFormLayoutData[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(ProductUIFormLayoutDataDAOQueryBean queryBean)
      throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(ProductUIFormLayoutDataDAOQueryBean queryBean) throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(
      ProductUIFormLayoutData[] aProductUIFormLayoutDatas,
      ProductUIFormLayoutDataDAOQueryBean queryBean)
      throws Exception {
    daoHelper.synchronize(aProductUIFormLayoutDatas, queryBean);
  }

  public void synchronize(
      ProductUIFormLayoutData[] aProductUIFormLayoutDatas,
      ProductUIFormLayoutDataDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<ProductUIFormLayoutData> callBack)
      throws Exception {
    daoHelper.synchronize(aProductUIFormLayoutDatas, queryBean, callBack);
  }

  public static class JdbcProductUIFormLayoutDataRowMapper
      implements RowMapper<ProductUIFormLayoutData> {

    public ProductUIFormLayoutData mapRow(ResultSet resultSet, int arg1) throws SQLException {
      ProductUIFormLayoutData object = new ProductUIFormLayoutData();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object formFieldId = null;

        formFieldId = resultSet.getObject(columnIndex++);

        object.setFormFieldIdNull(resultSet.getBoolean(columnIndex++));

        if (formFieldId != null) {

          setBeanValue(object, _DataObjectProperty.FormFieldId, formFieldId);
        }

        Object name = null;

        name = resultSet.getObject(columnIndex++);

        object.setNameNull(resultSet.getBoolean(columnIndex++));

        if (name != null) {

          setBeanValue(object, _DataObjectProperty.Name, name);
        }

        Object value = null;

        value = resultSet.getObject(columnIndex++);

        object.setValueNull(resultSet.getBoolean(columnIndex++));

        if (value != null) {

          setBeanValue(object, _DataObjectProperty.Value, value);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
